package com.xccwk.DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class UserDao {

	private static ThreadLocal<Connection> t1=new ThreadLocal<Connection>();


	static{
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() throws SQLException {
		Connection con=t1.get();
		if(con==null) {
			con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis_data?useSSL=false&useUnicode=true&characterEncoding=utf8",
					"root", "123456");
			t1.set(con);
		}
		return con;
	}


	public static void closeStatement(Statement stmt) {
		try {
			if(stmt!=null) {
				stmt.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	
	
	
	
	
	






}


